import json
from models import BaseModels
from sqlalchemy import Column, ForeignKey, String, DateTime, BigInteger, Integer, JSON, Uuid, Text


# 生产产品就流程记录数据

class Course(BaseModels):
    __tablename__ = 'courses'
    id = Column(BigInteger, autoincrement=True, primary_key=True, unique=True, nullable=False)
    sequence = Column(String(64), nullable=False, index=True, unique=True, comment="产品序列SN")
    aircraft_id = Column(Integer, ForeignKey("aircraft.id", ondelete='CASCADE'), index=True, comment="对应机种ID")
    tasks_id = Column(Integer, ForeignKey("tasks.id", ondelete='CASCADE'), index=True, comment="对应分任务编号ID")
    start = Column(DateTime, nullable=False, index=True, comment="开始时间")
    finish = Column(DateTime, nullable=True, index=True, comment="结束生产时间")
    mark = Column(Integer, nullable=False, index=True, comment="0未加工, 1oK, 2nG, 3报废")
    repair = Column(JSON, nullable=True, comment="返修路线")
    message = Column(Text, nullable=True, comment="产品报废原因说明")
    session = Column(Uuid, nullable=True, unique=True, comment="会话UUID4编号")

    def __repr__(self):
        return json.dumps({
            "course_id": self.id,
        })
